const app = getApp();
Page({
	data: {},
	onLoad: function(options) {
		var This = this;
		var for_data = options;
		app.request(app.apiDomain + "index.php?c=user&a=medal", {}, function(res) {
			This.setData({
				BadgeData:res.data.data.data,
				z_num:res.data.data.sum,
				z_total:res.data.data.total
			})
			This.li_for(for_data,res.data.data.data);//展开徽章
		});	
	},
	li_for:function(options,BadgeData){
		// console.log(BadgeData)
		if(options.id){//是否带了参数
			var data = [];
			data.currentTarget = [];
			data.currentTarget.dataset = [];
			//循环查询id
			for(var i=0;i < BadgeData.length;i++){
				for(var r=0; r < BadgeData[i].list.length;r++){
					if(options.id == BadgeData[i].list[r].id){
						data.currentTarget.dataset.dnum = i;
						data.currentTarget.dataset.xnum = r;
					}
				}
			};
			this.li_click(data)
		};
	},
	li_click:function(e){
		//点击展开徽章
		this.dnum = e.currentTarget.dataset.dnum;
		this.xnum = e.currentTarget.dataset.xnum;
		var data = this.data.BadgeData[this.dnum].list[this.xnum];
		this.win_id = data.id;
		if(data.show == 'on' || data.is_show == 'on'){
			var a = data.image_c;
			var type = 'on';
		}else{
			var a = data.image_d;
			var type = 'off';
		};
		this.setData({
			window_on:'on',
			window_img:a,
			window_type:'',
			window_number:data.constructor,
			window_point:data.point,
			remark_a:data.remark_a,
			remark_b:data.remark_b,
			is_show:data.is_show
		});
		//
		var b = this;
		setTimeout(function(g=b){
			g.setData({
				window_type:type,
			})
		},400);
	},
	window_off:function(){
		this.setData({
			window_on:'',
			window_img:''
		})
	},
	win_click:function(){
		var This = this;
		This.setData({
			['BadgeData['+This.dnum+'].list['+This.xnum+'].is_show']:'on',
			['BadgeData['+This.dnum+'].list['+This.xnum+'].show']:'off',
			is_show:'on'
		})
		// console.log(this.data.BadgeData[This.dnum].list)
		app.request(app.apiDomain + 'index.php?c=user&a=getMedal', {
			id:This.win_id
		}, function(res){
			console.log(res.data.info)
		});
	},
	onShareAppMessage: function() {
    var nickName = '';
    var userId = 0;
    try {
      nickName = wx.getStorageSync('nickname');
      userId = wx.getStorageSync('user_id');
    } catch (e) { }
    return {
      path: "/pages/index/index?user_id=" + userId,
      title: '每天多运动，不止健康，更可荣誉加身！',
      imageUrl: app.resourceDomain + 'canvas/healthy/img/badge/share_badge.jpg'
    }
	}
})
